package org.dromara.Nyt7RegionManagement.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.Nyt7RegionManagement.domain.vo.Nyt7RegionManagementVo;
import org.dromara.Nyt7RegionManagement.domain.bo.Nyt7RegionManagementBo;
import org.dromara.Nyt7RegionManagement.service.INyt7RegionManagementService;

/**
 * 区域管理
 *
 * @author Lion Li
 * @date 2024-12-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/Nyt7RegionManagement/Nyt7RegionManagement")
public class Nyt7RegionManagementController extends BaseController {

    private final INyt7RegionManagementService nyt7RegionManagementService;

    /**
     * 查询区域管理列表
     */
    @GetMapping("/list")
    public R<List<Nyt7RegionManagementVo>> list(Nyt7RegionManagementBo bo) {
        List<Nyt7RegionManagementVo> list = nyt7RegionManagementService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出区域管理列表
     */
    @SaCheckPermission("Nyt7RegionManagement:Nyt7RegionManagement:export")
    @Log(title = "区域管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(Nyt7RegionManagementBo bo, HttpServletResponse response) {
        List<Nyt7RegionManagementVo> list = nyt7RegionManagementService.queryList(bo);
        ExcelUtil.exportExcel(list, "区域管理", Nyt7RegionManagementVo.class, response);
    }

    /**
     * 获取区域管理详细信息
     *
     * @param regionId 主键
     */
    @SaCheckPermission("Nyt7RegionManagement:Nyt7RegionManagement:query")
    @GetMapping("/{regionId}")
    public R<Nyt7RegionManagementVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long regionId) {
        return R.ok(nyt7RegionManagementService.queryById(regionId));
    }

    /**
     * 新增区域管理
     */
    @SaCheckPermission("Nyt7RegionManagement:Nyt7RegionManagement:add")
    @Log(title = "区域管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody Nyt7RegionManagementBo bo) {
        return toAjax(nyt7RegionManagementService.insertByBo(bo));
    }

    /**
     * 修改区域管理
     */
    @SaCheckPermission("Nyt7RegionManagement:Nyt7RegionManagement:edit")
    @Log(title = "区域管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody Nyt7RegionManagementBo bo) {
        return toAjax(nyt7RegionManagementService.updateByBo(bo));
    }

    /**
     * 删除区域管理
     *
     * @param regionIds 主键串
     */
    @SaCheckPermission("Nyt7RegionManagement:Nyt7RegionManagement:remove")
    @Log(title = "区域管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{regionIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] regionIds) {
        return toAjax(nyt7RegionManagementService.deleteWithValidByIds(List.of(regionIds), true));
    }
}
